class Solution:
def groups(self, arr):
for i in range(5):
for j in range(i+1, 5, 1):
count1 = 0
count2 = 0
count0 = 0
for k in range(len(arr)):
if arr[k][i] ==1:
count1+=1
if arr[k][j] == 1:
count2+=1
if arr[k][i] == 0 and arr[k][j] == 0:
count0+=1
if count1>= len(arr)//2 and count2>= len(arr)//2 and count0 == 0:
return True
return False
t = int(input())
obj = Solution()
for _ in range(t):
n = int(input())
arr = []
for i in range(n):
k = list(map(int, input().split()))
arr.append(k)
if obj.groups(arr):
print("YES")
else:
print("NO")
// JAI MATA DI
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
# define LL22 long long
# define VI22 vector<int>
# define M22 map<int, int>
# define PII22 pair<int, int>
# define VII22 vector<PII22>
# define NV22(i, a, b) for(int i=a; i<b; i++)
# define F22 first
# define S22 second
# define setBits(x) builtin_popcount(x)
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
LL22 t22;
cin>>t22;
while(t22--){
int n;
cin>>n;
int a[n][5];
for(int i=0; i<n; i++){
for(int j=0; j<5; j++){
cin>>a[i][j];
}
}
string ans="No";
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
if(i!=j){
int d1=i, d2=j, c1=0, c2=0, c=0;
for(int k=0; k<n; k++){
if(a[k][d1]==1) c1++;
if(a[k][d2]==1) c2++;
if(a[k][d1]==0&&a[k][d2]==0) c++;
}
if(c1>=n/2 and c2>=n/2 and c==0){
ans="Yes";
break;
}
}
}
if(ans=="Yes") break;
}
cout<<ans<<endl;
}
return 0;
}
//NEERAJ VERMA
1609A - Divide and Multiply | 149B - Martian Clock |
205A - Little Elephant and Rozdil | 1609B - William the Vigilant |
978B - File Name | 1426B - Symmetric Matrix |
732B - Cormen --- The Best Friend Of a Man | 1369A - FashionabLee |
1474B - Different Divisors | 1632B - Roof Construction |
388A - Fox and Box Accumulation | 451A - Game With Sticks |
768A - Oath of the Night's Watch | 156C - Cipher |
545D - Queue | 459B - Pashmak and Flowers |
1538A - Stone Game | 1454C - Sequence Transformation |
165B - Burning Midnight Oil | 17A - Noldbach problem |
1350A - Orac and Factors | 1373A - Donut Shops |
26A - Almost Prime | 1656E - Equal Tree Sums |
1656B - Subtract Operation | 1656A - Good Pairs |
1367A - Short Substrings | 87A - Trains |
664A - Complicated GCD | 1635D - Infinite Set |